package TechStuff;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import Controllers.ControllerCreater;
import Controllers.ControllerCreaterInterfece;

public class ControllerCreaterStarter extends RmiStarter {
	private PawnControllerStarter chessPieceControllerStarter;
	private BoardControllerStarter boardControllerStarter;
	private KnightControllerStarter knightControllerStarter;
	private RookControllerStarter rookControllerStarter;
	private QueenControllerStarter queenControllerStarter;
	private KingControllerStarter kingControllerStarter;
	private BishopControllerStarter bishopControllerStarter;

	public ControllerCreaterStarter(PawnControllerStarter chessPieceControllerStarter,
									BoardControllerStarter boardControllerStarter,
									KnightControllerStarter knightControllerStarter,
									RookControllerStarter rookControllerStarter,
									QueenControllerStarter queenControllerStarter,
									KingControllerStarter kingControllerStarter,
									BishopControllerStarter bishopControllerStarter)
									  {
		super(ControllerCreaterInterfece.class);
		this.chessPieceControllerStarter = chessPieceControllerStarter;
		this.boardControllerStarter = boardControllerStarter;
		this.knightControllerStarter = knightControllerStarter;
		this.rookControllerStarter = rookControllerStarter;
		this.queenControllerStarter = queenControllerStarter;
		this.kingControllerStarter = kingControllerStarter;
		this.bishopControllerStarter = bishopControllerStarter;
		doCustomRmiHandling();
	}

	@Override
	public void doCustomRmiHandling() {
		try {
			ControllerCreaterInterfece obj = new ControllerCreater(	chessPieceControllerStarter, 
																	boardControllerStarter, 
																	knightControllerStarter,
																	rookControllerStarter,
																	queenControllerStarter,
																	kingControllerStarter,
																	bishopControllerStarter);
			ControllerCreaterInterfece stub = (ControllerCreaterInterfece) UnicastRemoteObject.exportObject(obj, 0);

		    // Bind the remote object's stub in the registry
		    Registry registry = LocateRegistry.getRegistry();
		    registry.bind(ControllerCreaterInterfece.name, stub);

		    System.err.println("ControllerCreaterInterfece ready");
		} catch (Exception e) {
		    System.err.println("ControllerCreaterInterfece exception: " + e.toString());
		    e.printStackTrace();
		}		
	}

}
